# -*- coding: utf-8 -*-
# @Time         : 12:26 2025/2/25
# @Author       : Chris
# @Description  :
from __future__ import annotations

from typing import List, Optional

import httpx
from xgj.types.order_detail import OrderDetail

from .._base_client import (
    make_request_options,
)
from .._models import BaseModel
from .._resource import SyncAPIResource
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from ..pagination import SyncPage
from ..types.product_detail import ProductDetail

__all__ = ["Orders"]


class Orders(SyncAPIResource):
    def list(
        self,
        page_no: int,
        page_size: int,
        confirm_time: Optional[List[int]] = None,
        consign_time: Optional[List[int]] = None,
        order_status: Optional[int] = None,
        order_time: Optional[List[int]] = None,
        pay_time: Optional[List[int]] = None,
        refund_status: Optional[int] = None,
        refund_time: Optional[List[int]] = None,
        update_time: Optional[List[int]] = None,
        *,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
    ) -> SyncPage[OrderDetail]:
        """
        查询订单。

        Args:
            confirm_time: 订单成交时间
            consign_time: 卖家发货时间
            order_status: 订单状态
            order_time: 买家下单时间
            page_no: 页码
            page_size: 每页行数, 当翻页获取的条数（page_no*page_size）超过1万，接口将报错，请尽可能的细化搜索条件
            pay_time: 买家支付时间
            refund_status: 退款状态
            refund_time: 退款成功时间
            update_time: 订单更新时间

        Returns:
            构建的字典
        """
        return self._post_api_list(
            "/order/list",
            page=SyncPage[OrderDetail],
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            model=OrderDetail,
            body={
                "confirm_time": confirm_time,
                "consign_time": consign_time,
                "order_status": order_status,
                "order_time": order_time,
                "page_no": page_no,
                "page_size": page_size,
                "pay_time": pay_time,
                "refund_status": refund_status,
                "refund_time": refund_time,
                "update_time": update_time,
            },
        )

    def detail(
        self,
        order_no: int,
        *,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
    ) -> ProductDetail:
        """
        查询订单详情。

        Args:
          order_no: 咸鱼订单号
        """
        return self._post(
            f"/order/detail",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ProductDetail,
            body={"order_no": order_no}
        )

    def ship(
        self,
        express_code: str,
        express_name: str,
        order_no: str,
        waybill_no: str,
        ship_address: Optional[str] = None,
        ship_area_name: Optional[str] = None,
        ship_city_name: Optional[str] = None,
        ship_district_id: Optional[int] = None,
        ship_mobile: Optional[str] = None,
        ship_name: Optional[str] = None,
        ship_prov_name: Optional[str] = None,
        *,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
    ) -> BaseModel:
        """
        订单发货。

        :param express_code: 快递公司代码
        :param express_name: 快递公司名称
        :param order_no: 闲鱼订单号
        :param waybill_no: 快递单号
        :param ship_address: 寄件方详细地址
        :param ship_area_name: 寄件方所在地区
        :param ship_city_name: 寄件方所在城市
        :param ship_district_id: 寄件方所在地区ID
        :param ship_mobile: 寄件方号码
        :param ship_name: 寄件方姓名
        :param ship_prov_name: 寄件方所在省份
        :return: 构造的字典
        """
        return self._post(
            "/order/ship",
            body={
                "express_code": express_code,
                "express_name": express_name,
                "order_no": order_no,
                "waybill_no": waybill_no,
                "ship_address": ship_address,
                "ship_area_name": ship_area_name,
                "ship_city_name": ship_city_name,
                "ship_district_id": ship_district_id,
                "ship_mobile": ship_mobile,
                "ship_name": ship_name,
                "ship_prov_name": ship_prov_name,
            },
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=BaseModel
        )
